package graphicUserInterface.mainInterface.screens;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;

public class FirstScreen extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7807239678570421442L;
	
	/* *********************************************************
	 * Attributes
	 * ********************************************************* */
	private JButton _next;
	private JPanel _center;
	
	/* *********************************************************
	 * Constructor(s)
	 * ********************************************************* */
	/**
	 * basic constructor :
	 * just initialize the main elements but do not draw all the 
	 * screen (see draw method : {@link #draw()} )
	 * @param nextButtonAction action to be perform by the next button
	 */
	public FirstScreen(ActionListener nextButtonAction){
		super();
		System.out.println("GUI:FirstScreen init");
		//first set the layout to add things vertically
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		//add a title :
		this.add(new JLabel("Hello people ! And welcome in HINB !"));
		//prepare a JPanel to be displayed under the title
		_center = new JPanel();
		_center.setLayout(new GridLayout(2,2));
		//JFD
		_center.setBackground(Color.CYAN);
		//end of JFD
		this.add(_center);
		_next = new JButton("start by calibration !");
		_next.addActionListener(nextButtonAction);
	}
	
	
	/* *********************************************************
	 * Instance Methods
	 * ********************************************************* */
	/**
	 * draw the screen : remove all component first, then draw and 
	 * finally call the validate method on the current screen
	 */
	public void draw(){
		_center.removeAll();
		//TODO check if removeAll remove the layout ...
		JTextPane fstText = new JTextPane();
		fstText.setText("HINB Is Not BlobbyVolley, it's way better!\n" +
				"\nHINB is a simple volleyball game where the players " +
				"are controlled by the movements of a player's hand in" +
				" front of his webcam.\n\nEach player is represented " +
				"by a snowman, a penguin being the ball. The net is a " +
				"pine tree\n\nMovements to the left or to the right " +
				"makes the snowmen move right or left. Rapid up " +
				"movements make them jump.");
		fstText.setEditable(false);
		_center.add(fstText);
		
		JLabel fstPict = new JLabel(
				new ImageIcon("assets/images/screenshot.jpg"));
		
		_center.add(fstPict);
		
		JLabel sndPict = new JLabel(
				new ImageIcon("assets/images/screenshot.jpg"));
		_center.add(sndPict);
		
		JPanel subPart = new JPanel();
		subPart.setLayout(new BoxLayout(subPart, BoxLayout.Y_AXIS));
		//create the text for the last part
		JTextPane sndText = new JTextPane();
		sndText.setText("Are you ready to smash the penguin?");
		sndText.setEditable(false);
		subPart.add(sndText);
		//then add the button
		subPart.add(_next);
		_center.add(subPart);
		//JFD
		fstPict.setBackground(Color.ORANGE);
		sndPict.setBackground(Color.GREEN);
		//end of JFD
		this.validate();
		System.out.println("GUI:FristScreen drawing job over");
	}
}
